package cn.yunhe.services;

import cn.yunhe.dao.IFoodDaoMapper;
import cn.yunhe.entity.merchantsentity.Food;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * 周依博
 */
public class UpdateFoodService {
    SqlSession session =null;
    IFoodDaoMapper foodDaoMapper =null;
    public Food getNewsById(int fid){
        Food food;
        try{
            session = SqlSessionFactoryUtil.getSqlSession();
            foodDaoMapper =session.getMapper(IFoodDaoMapper.class);
            food = foodDaoMapper.getNewsById(fid);
        }finally {
            session.close();
        }
        return food;
    }
    public int updateFood(Food food){
        int result;
        try{
            session = SqlSessionFactoryUtil.getSqlSession();
            foodDaoMapper =session.getMapper(IFoodDaoMapper.class);
            result=foodDaoMapper.updateFood(food);
            session.commit();
        }finally {
            session.close();
        }
        return result;
    }
}
